﻿//https://leetcode.cn/problems/longest-substring-without-repeating-characters/

class Solution {
public:
    int lengthOfLongestSubstring(string s)
    {
        int n = s.size();
        int left = 0, right = 0;
        int hash[128] = { 0 };
        int len = 0;
        while (right < n)
        {
            //进窗口
            hash[s[right]]++;
            //判断条件
            while (hash[s[right]] > 1)
            {
                //出窗口
                hash[s[left++]]--;
            }

            //更新结果
            len = max(len, right - left + 1);
            right++;
        }
        return len;
    }
};